package com.jack006.article.stream;

import com.jack006.pojo.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @Classname StreamServiceImpl
 * @Description 开启绑定器，绑定通道Channel
 * @Date 2021-08-12 08:38
 * @Created by jack
 */
@Service
@EnableBinding(MyStreamChannel.class)
public class StreamServiceImpl implements StreamService {

    @Autowired
    private MyStreamChannel myStreamChannel;

    @Override
    public void sendMsg() {
        AppUser user = new AppUser();
        user.setId("1001");
        user.setNickname("jack006");
        // 消息绑定器发送 mq;
        myStreamChannel.output().send(MessageBuilder.withPayload(user).build());
    }

    @Override
    public void eat(String food) {
        myStreamChannel.output().send(MessageBuilder.withPayload(food).build());
    }
}
